﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PubSubLite
{
    [Serializable]
    internal class Message<T> : IMessage<T>
    {
        public Message(T data)
            : this(data, string.Empty)
        {
            
        }

        public Message(T data, string category)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data cannot be null");
            }
            _category = category;
            _data = data;
        }

        public Message(T data, Guid correlatingMessageID)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data cannot be null");
            }
            if (correlatingMessageID == Guid.Empty)
            {
                throw new ArgumentException("correlatingMessageID cannot be empty");
            }
            _data = data;
            ((IMessageBase)this).CorrelatingMessageID = correlatingMessageID;
        }

        private Guid _messageID = Guid.NewGuid();
        private string _category = string.Empty;
        private T _data;

        Guid IMessageBase.MessageID
        {
            get { return _messageID; }
        }

        Guid IMessageBase.CorrelatingMessageID
        {
            get;
            set;
        }

        Type IMessageBase.MessageDataType
        {
            get { return typeof(T); }
        }

        public virtual bool IsCommand
        {
            get { return false; }
        }

        public virtual bool IsInternal
        {
            get { return false; }
        }

        string IMessageBase.Category
        {
            get { return _category; }
        }

        T IMessage<T>.Data
        {
            get { return _data; }
        }
    }
}
